#include "QuadMesh.h"
#include "VertexList.h"
#include "TriangleList.h"
#include "ObjMesh.h"

QuadMesh::QuadMesh(DAEFloat3 origin, float width, float height):m_Origin(origin),m_Width(width),m_Height(height),m_pMesh(0)
{
	VertexList* pVertexList = VertexList::Create3DPosTexVL(4);

	DAEFloat3 p1 = m_Origin;
	p1.x += m_Width;
	DAEFloat3 p2 = p1;
	p2.y += m_Height;
	DAEFloat3 p3 = m_Origin;
	p3.y += m_Height;

	pVertexList->AddVertexData(0,POSITION, &m_Origin);
	pVertexList->AddVertexData(1,POSITION, &p1);
	pVertexList->AddVertexData(2,POSITION, &p2);
	pVertexList->AddVertexData(3,POSITION, &p3);

	DAEFloat2 uv(0,0);
	pVertexList->AddVertexData(0,TEXCOORD,&uv);
	uv.x = 1;
	pVertexList->AddVertexData(1,TEXCOORD,&uv);
	uv.y = 1;
	pVertexList->AddVertexData(2,TEXCOORD,&uv);
	uv.SetValues(0,1);
	pVertexList->AddVertexData(3,TEXCOORD,&uv);

	TriangleList* pTriangleList = new TriangleList(2);
	pTriangleList->AddIndexedFace(2,1,0);
	pTriangleList->AddIndexedFace(3,2,0);

	m_pMesh = new ObjMesh(pVertexList,pTriangleList);
}


QuadMesh::~QuadMesh(void)
{
	if ( m_pMesh != 0 )
		delete m_pMesh;
}
